package com.xupt.advertisement.Advertisement.controllers;

import com.xupt.advertisement.Advertisement.entities.User;
import com.xupt.advertisement.Advertisement.repositories.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping(value = "/api/users")
public class UserController {

    @Autowired
    private UserRepository userRepository;

    @GetMapping(value = "/{userId}")
    ResponseEntity getUserInfo(@PathVariable Long userId) throws Exception {

        User user = userRepository.findById(userId);
        Map<String, String> result = new HashMap<>();
        result.put("userName", user.getUsername());
        result.put("mobile", user.getMobilePhone());
        result.put("status", "success");
        return new ResponseEntity<>(result, HttpStatus.OK);
    }
}


